/**
 * Created by nemo on 2017/1/25.
 */
var path = require('path');
var express = require('express');

var app = express();
var indexRouter = require('./routes/index');
var userRouter = require('./routes/users');

app.set('views', path.join(__dirname, 'views'));//设置存放模板文件的目录
// app.set('views engine', 'ejs');
app.set('view engine', 'ejs');

// app.get('/', function(req, res) {
//     res.send('hello, myl111ive');
// });
//
// app.get('/users/:name', function(req, res) {
//     res.send('hello,' + req.params.name);
// })
app.use(function(req, res, next){
    console.log('1');
    next(new Error('haha'));
})

app.use(function(req, res, next) {
    console.log('2');
    next();
})
app.use('/', indexRouter);
app.use('/users', userRouter);
//错误处理
app.use(function(err, req, res, next) {
    console.error(err.stack);
    res.status(500).send('Something broke!');
});


app.listen(3000);

